#pragma once

#include <sys_def.h>

// 严格全序关系的左右元
typedef struct {
	u32_s left;
	u32_s right;
} order_t;

// 如果whether_order为非0，保持left和right返回；如果为0，颠倒后返回。
static inline order_t get_order(u32_s left, u32_s right,
				u32_s whether_order) {
	u32_s order_all_1_else_all_0 = -whether_order;
	u32_s order_xor_else_all_0 = order_all_1_else_all_0 & (left ^ right);
	u32_s order_left_else_right = right ^ order_xor_else_all_0;
	u32_s order_right_else_left = left ^ order_xor_else_all_0;
	order_t order = {
		.left = order_left_else_right,
		.right = order_right_else_left,
	};
	return order;
}
